/**************************************************************************************************
* Title: SumKeyboard.cpp
* Author: Gael Huber
* Description: Manages calls to get the keyboard state and tracks changes between calls.
**************************************************************************************************/
#include "SumKeyboard.h"

/**************************************************************************************************
* Default constructor
**************************************************************************************************/
Keyboard::Keyboard(void) 
	: keyboard(0)
{ }

/**************************************************************************************************
* Constructor given the device
**************************************************************************************************/
Keyboard::Keyboard(LPDIRECTINPUT8 input) 
	: keyboard(0)
{
	// Initialize the keyboard device
	input->CreateDevice(GUID_SysKeyboard,	// Default keyboard ID being used
						&keyboard,	// Keyboard interface
						NULL);
	
	// Set the data format to keyboard format
	keyboard->SetDataFormat(&c_dfDIKeyboard);

	// Set the control you will have over the keyboard
	keyboard->SetCooperativeLevel(GetHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
	
}

/**************************************************************************************************
* Destructor
**************************************************************************************************/
Keyboard::~Keyboard(void) {
	if(keyboard)	keyboard->Unacquire();
}

/**************************************************************************************************
* Updates the keyboard state
**************************************************************************************************/
void Keyboard::update(void) {
	// Get access to keyboard
	keyboard->Acquire();

	// Get the input data
	keyboard->GetDeviceState(256, (LPVOID)keyState);
}